<template>
	<view class="add-student">
		<u-form labelPosition="left" :model="userInfo" labelWidth="240rpx" ref="form" :rules="rules">
			<view class="form-label-top margin-top-3">
				<u-form-item label="姓名" prop="name" borderBottom required v-if="fields_list.name">
					<view class="d-flex justify-space-between">
						<view>
							<u-input v-model="userInfo.name" placeholder="请输入姓名" border="none"
								v-if="fields_list.name" />

							<view style="margin-top: 36rpx;" v-if="fields_list.sex">
								<u-radio-group v-model="userInfo.sex" @change="groupChange">
									<u-radio label="男" :name="1" />
									<u-radio label="女" :name="2" customStyle="margin-left: 60rpx;" />
								</u-radio-group>
							</view>
						</view>
						<u-upload v-if="fields_list.head_img" :fileList="fileList1" @afterRead="afterRead"
							@delete="deletePic" name="1" multiple :maxCount="1"></u-upload>
					</view>
				</u-form-item>
			</view>
			<view class="form-label-top margin-top-3">
				<u-form-item label="手机号" prop="userInfo.phone" borderBottom ref="item1" v-if="fields_list.mobile">
					<u-input placeholder="请输入手机号" v-model="userInfo.phone" border="none" type="number"></u-input>
				</u-form-item>
				<u-form-item label="监护人" prop="userInfo.custodian" borderBottom ref="item1" required
					v-if="fields_list.custodian">
					<u-input placeholder="请输入监护人名字" v-model="userInfo.custodian" border="none"></u-input>
				</u-form-item>

				<u-form-item label="监护人手机号" prop="userInfo.custodian_mobile" borderBottom ref="item1" required
					v-if="fields_list.custodian_mobile">
					<u-input placeholder="请输入监护人手机号" v-model="userInfo.custodian_mobile" border="none"></u-input>
				</u-form-item>
				<u-form-item label="监护人关系" prop="custodian_relation" borderBottom v-if="fields_list.custodian_relation"
					required>
					<view @click="show = true" class="flex-between">
						<u-text :text="userInfo.custodian_relation" v-if="userInfo.custodian_relation" color="#303133">
						</u-text>
						<u-text text="请选择监护人关系" v-else color="#c0c4cc"></u-text>
						<u-icon name="arrow-right" color="#BEBEBE" size="28rpx" customStyle="margin-left: 30rpx;">
						</u-icon>
					</view>
					<u-picker :show="show" :columns="columns" keyName="label" @confirm="confirm" @cancel="show = false">
					</u-picker>
				</u-form-item>

				<view class="group">
					<u-form-item label="监护人2" prop="userInfo.custodian_t" borderBottom ref="item1"
						v-if="fields_list.custodian_t">
						<u-input placeholder="请输入监护人2名字" v-model="userInfo.custodian_t" border="none"></u-input>
					</u-form-item>

					<u-form-item label="监护人2手机号" prop="userInfo.custodian_t_mobile" borderBottom ref="item1"
						v-if="fields_list.custodian_t_mobile">
						<u-input placeholder="请输入监护人2手机号" v-model="userInfo.custodian_t_mobile" border="none"></u-input>
					</u-form-item>

					<u-form-item label="监护人2关系" prop="custodian_t_relation" borderBottom
						v-if="fields_list.custodian_t_relation">
						<view @click="custodian_show = true" class="flex-between">
							<u-text :text="userInfo.custodian_t_relation" v-if="userInfo.custodian_t_relation"
								color="#303133">
							</u-text>
							<u-text text="请选择监护人2关系" v-else color="#c0c4cc"></u-text>
							<u-icon name="arrow-right" color="#BEBEBE" size="28rpx" customStyle="margin-left: 30rpx;">
							</u-icon>
						</view>
						<u-picker :show="custodian_show" :columns="col_list" keyName="label" @confirm="custodian_list"
							@cancel="custodian_show = false">
						</u-picker>
					</u-form-item>


					<u-form-item label="身份证号" prop="id_card" borderBottom v-if="fields_list.id_card">
						<u-input v-model="userInfo.id_card" placeholder="请输入身份证号" border="none" type="number" />
					</u-form-item>
					<u-form-item label="婚姻状况" prop="marital_status" borderBottom v-if="fields_list.marital_status">
						<view @click="showstatus = true" class="flex-between">
							<u-text :text="userInfo.marital_status" v-if="userInfo.marital_status" color="#303133">
							</u-text>
							<u-text text="请选择婚姻状况" v-else color="#c0c4cc"></u-text>
							<u-icon name="arrow-right" color="#BEBEBE" size="28rpx" customStyle="margin-left: 30rpx;">
							</u-icon>
						</view>
						<u-picker :show="showstatus" :columns="columns_status" keyName="label" @confirm="confirm_status"
							@cancel="showstatus = false">
						</u-picker>
					</u-form-item>

					<u-form-item label="生日" prop="birthday" borderBottom v-if="fields_list.birthday">
						<view @click="showBirthdayPicker = true" class="flex-between">
							<u-text :text="userInfo.birthday" v-if="userInfo.birthday" color="#303133"></u-text>
							<u-text text="请选择生日" v-else color="#c0c4cc"></u-text>
							<u-icon name="arrow-right" color="#BEBEBE" size="28rpx"></u-icon>
						</view>
						<u-datetime-picker v-model="defaultBirthday" :show="showBirthdayPicker" mode="date"
							:minDate="minDate" :maxDate="maxDate" @confirm="confirmBirthday"
							@cancel="showBirthdayPicker = false" />
					</u-form-item>
					<u-form-item label="城市" prop="occupation_relation" borderBottom
						v-if="fields_list.province || fields_list.area || fields_list.city">
						<view class="flex-between">
							<pick-regions :defaultRegion="defaultRegionCode" @getRegion="handleGetRegion">
								<u-text :text="regionName" v-if="regionName" color="#303133"></u-text>
								<u-text text="请选择城市" v-else color="#c0c4cc"></u-text>
							</pick-regions>
							<u-icon name="arrow-right" color="#BEBEBE" size="28rpx"></u-icon>
						</view>
					</u-form-item>
					<u-form-item label="邮箱" prop="email" borderBottom v-if="fields_list.email">
						<u-input v-model="userInfo.email" placeholder="请输入邮箱" border="none" type="number" />
					</u-form-item>
					<u-form-item label="身高" prop="height" borderBottom v-if="fields_list.height">
						<u-input v-model="userInfo.height" placeholder="请输入身高" border="none" type="number" />
					</u-form-item>
					<u-form-item label="体重" prop="weight" borderBottom v-if="fields_list.weight">
						<u-input v-model="userInfo.weight" placeholder="请输入体重" border="none" type="number" />
					</u-form-item>
					<u-form-item label="年龄" prop="age" borderBottom v-if="fields_list.age">
						<u-input v-model="userInfo.age" placeholder="请输入年龄" border="none" type="number" />
					</u-form-item>
					<!-- <u-form-item label="学校" prop="school" borderBottom v-if="fields_list.graduate">
						<u-input v-model="userInfo.school" placeholder="请输入学校" border="none" />
					</u-form-item> -->
					<!-- <u-form-item label="班级" prop="class_s" borderBottom v-if="fields_list.marital_status">
						<u-input v-model="userInfo.class_s" placeholder="请输入班级" border="none" />
					</u-form-item> -->
					<u-form-item label="地址" prop="address" borderBottom v-if="fields_list.address">
						<u-input v-model="userInfo.address" placeholder="请输入地址" border="none" />
					</u-form-item>
					<u-form-item label="公司" prop="company" borderBottom v-if="fields_list.company">
						<u-input v-model="userInfo.company" placeholder="请输入公司" border="none" />
					</u-form-item>
					<u-form-item label="学校" prop="graduate" borderBottom v-if="fields_list.graduate">
						<u-input v-model="userInfo.graduate" placeholder="请输入学校" border="none" />
					</u-form-item>
					<u-form-item label="年级" prop="grade_name" borderBottom v-if="fields_list.grade_name">
						<u-input v-model="userInfo.grade_name" placeholder="请输入年级" border="none" />
					</u-form-item>
					<u-form-item label="班级" prop="class_name" borderBottom v-if="fields_list.class_name">
						<u-input v-model="userInfo.class_name" placeholder="请输入班级" border="none" />
					</u-form-item>
					

					<u-form-item label="职业" prop="occupation_relation" borderBottom v-if="fields_list.occupation">
						<view @click="showoccupation = true" class="flex-between">
							<u-text :text="userInfo.occupation_relation" v-if="userInfo.occupation_relation"
								color="#303133">
							</u-text>
							<u-text text="请选择职业" v-else color="#c0c4cc"></u-text>
							<u-icon name="arrow-right" color="#BEBEBE" size="28rpx" customStyle="margin-left: 30rpx;">
							</u-icon>
						</view>
						<u-picker :show="showoccupation" :columns="occupation_status" keyName="label"
							@confirm="occupation_list" @cancel="showoccupation = false">
						</u-picker>
					</u-form-item>
				</view>



				<!-- <view class="group" v-for="(item,index) in fields_list" :key="index">
					<u-form-item :label="item.name" prop="item.field_name" borderBottom>
						<u-input v-model="userInfo.id_card" :placeholder="'请输入' + item.name" border="none" type="text" />
					</u-form-item>
					
				</view> -->

				<!-- <block v-for="(item, index) in fields_list" :key="index">

					<u-form-item :label="item.name" prop="phone" borderBottom>
						<u-input v-model="item.remark" :placeholder="'请输入' + item.name" border="none" type="text"
							v-if="item.field_type == 'input'" />

						<u-radio-group v-model="item.remark" v-if="item.field_type == 'radio'">
							<u-radio label="男" :name="`男`" @select="sexSelect" />
							<u-radio label="女" :name="`女`" :customStyle="{ marginLeft: '60rpx' }" @select="sexSelect" />
						</u-radio-group>

						<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
							:maxCount="1" v-if="item.field_type == 'upload'"></u-upload>

						<view @click="showstatus = true" class="flex-between"
							v-if="item.field_type == 'select' && item.field_name == 'marital_status'">
							<u-text :text="userInfo.marital_status" v-if="userInfo.marital_status" color="#303133">
							</u-text>
							<u-text :text="'请选择' + item.name" v-else color="#c0c4cc"></u-text>
							<u-icon name="arrow-right" color="#BEBEBE" size="28rpx" customStyle="margin-left: 30rpx;">
							</u-icon>
						</view>
						<u-picker :show="showstatus" :columns="item.options" keyName="label" @confirm="confirm_status"
							v-if="item.field_type == 'select' && item.field_name == 'marital_status'"
							@cancel="showstatus = false">
						</u-picker>

						<view @click="showoccupation = true" class="flex-between"
							v-if="item.field_type == 'select' && item.field_name == 'occupation'">
							<u-text :text="userInfo.occupation_relation" v-if="userInfo.occupation_relation"
								color="#303133">
							</u-text>
							<u-text :text="'请选择' + item.name" v-else color="#c0c4cc"></u-text>
							<u-icon name="arrow-right" color="#BEBEBE" size="28rpx" customStyle="margin-left: 30rpx;">
							</u-icon>
						</view>
						<u-picker :show="showoccupation" :columns="item.options" keyName="label"
							@confirm="occupation_list"
							v-if="item.field_type == 'select' && item.field_name == 'occupation'"
							@cancel="showoccupation = false">
						</u-picker>


						<view @click="show = true" class="flex-between"
							v-if="item.field_type == 'select' && item.field_name == 'custodian_relation'">
							<u-text :text="userInfo.custodian_relation" v-if="userInfo.custodian_relation"
								color="#303133">
							</u-text>
							<u-text :text="'请选择' + item.name" v-else color="#c0c4cc"></u-text>
							<u-icon name="arrow-right" color="#BEBEBE" size="28rpx" customStyle="margin-left: 30rpx;">
							</u-icon>
						</view>
						<u-picker :show="show" :columns="item.options" keyName="label" @confirm="confirm"
							v-if="item.field_type == 'select' && item.field_name == 'custodian_relation'"
							@cancel="show = false">
						</u-picker>

						<view @click="showBirthdayPicker = true" class="flex-between"
							v-if="item.field_type == 'select' && item.field_name == 'birthday'">
							<u-text :text="userInfo.birthday" v-if="userInfo.birthday" color="#303133"></u-text>
							<u-text :text="'请选择' + item.name" v-else color="#c0c4cc"></u-text>
							<u-icon name="arrow-right" color="#BEBEBE" size="28rpx"></u-icon>
						</view>
						<u-datetime-picker v-model="defaultBirthday" :show="showBirthdayPicker" mode="date"
							v-if="item.field_type == 'select' && item.field_name == 'birthday'" :minDate="minDate"
							:maxDate="maxDate" @confirm="confirmBirthday" @cancel="showBirthdayPicker = false" />
							
						<view  class="flex-between" v-if="item.field_type == 'select' && item.field_name == 'province'">
							<pick-regions :defaultRegion="defaultRegionCode" @getRegion="handleGetRegion" v-if="item.field_type == 'select' && item.field_name == 'province'">
								<u-text :text="regionName" v-if="regionName" color="#303133"></u-text>
								<u-text :text="'请选择' + item.name" v-else color="#c0c4cc"></u-text>
							</pick-regions>
							<u-icon name="arrow-right" color="#BEBEBE" size="28rpx"></u-icon>
						</view>

					</u-form-item>
				</block> -->
			</view>
		</u-form>

		<view class="bottom-add-btn"
			style="width: 100%; height: 160rpx;background-color: #fff;position: fixed;z-index: 9;bottom: 0;left: 0;">
			<u-button text="确认添加" shape="circle" @click="add"
				color="linear-gradient(0deg, rgb(47, 117, 250) 0%, rgb(82, 142, 255) 100%)"></u-button>
		</view>
	</view>
</template>

<script>
	import pickRegions from '../components/pick-regions/pick-regions.vue'
	import {
		formatDate
	} from "@/utils/util.js";
	const train = require("@/api/train/index.js");
	export default {
		components: {
			pickRegions
		},
		data() {
			return {
				custodian_show: false, //监护人2关系
				showstatus: false, //婚姻状况
				show: false, //亲属关系
				showoccupation: false, //职业
				columns: [], //亲属关系
				columns_status: [], //婚姻状况
				col_list: [], //监护人关系
				occupation_status: [], //职业
				occupa: [],
				// sss: [ ],
				marital_s: [],

				showBirthdayPicker: false,
				formData: {},
				minDate: new Date(new Date().getFullYear() - 100, 0, 1).getTime(),
				maxDate: Date.now(),
				Default: new Date(new Date().getFullYear() - 20, 0, 1).getTime(),
				field: [],
				formStr: "",
				fileList1: [],
				rules: {
					// 'userInfo.name': {
					// 	type: 'string',
					// 	required: true,
					// 	message: '请填写姓名',
					// 	trigger: ['blur', 'change']
					// },
					// 'userInfo.sex': {
					// 	type: 'string',
					// 	max: 1,
					// 	required: true,
					// 	message: '请选择男或女',
					// 	trigger: ['blur', 'change']
					// },
				},

				userInfo: {
					name: '', //姓名
					sex: '', //性别
					custodian: '', //监护人
					birthday: '', //birthday
					phone: '', //电话号码
					gender: 1, //
					kinship: '', //
					height: '', //身高
					weight: '', //体重
					age: '', //年龄
					school: '', //毕业学校
					class_s: '', //班级
					avatar: '', //头像
					custodian_relation: '', //监护人关系
					custodian_relation_id: '', //监护人关系id
					address: '', //详细地址
					marital_status: '', //婚姻状况
					marital_s_id: '', //婚姻状况id
					company: '', //公司
					graduate: "", //毕业学校
					id_card: '', //身份证号
					occupation_relation: '', //职业
					occupation_relation_id: '', //职业id
					email: '', //邮箱
					province: '', //省份
					city: '', //城市
					area: '', //区/县
					custodian_mobile: "", //监护人手机号
					custodian_t_relation: "", //监护人2关系
					custodian_t: "", //监护人2名称
					custodian_t_mobile: "", //监护人2手机号
					custodian_t_relation_id: '' ,//监护人2名称id
					grade_name:'',//年级
					class_name:'',//班级
				},
				formData: {
					gender: 1
				},
				showBirthdayPicker: false,
				showBirthdayPicker: false,
				defaultBirthday: new Date(new Date().getFullYear() - 20, 0, 1).getTime(),
				url_phone: '',
				showKinshipPicker: false,
				columnn: {
					kinship: [
						// ['母亲','12','23'],
						// ["父亲", "母亲", "爷爷", "奶奶", "其他"],
						[{
								name: '父亲',
								id: '12'
							}

						]
					],

				},
				product_id: '',
				fields_list: {},
				region: [],
				// defaultRegion:['广东省','广州市','番禺区'],
				defaultRegion: [],
				defaultRegionCode: '440113',
				defaultRegionCode: '',
			};
		},
		computed: {
			regionName() {
				// 转为字符串
				return this.region.map(item => item.name).join(' ')
			}
		},
		onLoad(options) {
			this.product_id = options.id
			if (this.product_id) {
				this.getStudentField()
			}
			this.conf()
		},
		methods: {
			// 获取选择的地区
			handleGetRegion(region) {
				// let province = {}
				this.region = region
				this.userInfo.province = region[0].code
				this.userInfo.city = region[1].code
				this.userInfo.area = region[2].code
				region.forEach((item, index) => {
					// province[item.name] = item.code
				});
			},
			async getStudentField() {
				let params = {
					app_id: this.$https.weixinAppId,
					project_id: getApp().globalData.projectId,
					product_id: this.product_id
				}
				let res = await train.getStudentField(params);
				if (res.code == 1) {
					this.fields_list = res.data.res
				}
			},
			groupChange(n) {
				this.userInfo.sex = n
			},
			async conf() {
				let params = {
					app_id: this.$https.weixinAppId,
					project_id: getApp().globalData.projectId,
				}
				let res = await train.conf(params);
				if (res.code == 1) {
					this.columns.push(
						res.data.list.custodian_relation_list
					)
					this.col_list.push(
						res.data.list.custodian_relation_list
					)
					this.columns_status.push(
						res.data.list.marital_status_list
					)
					this.occupation_status.push(
						res.data.list.occupation_list
					)
				}
			},
			// 亲属关系
			confirm(e) {
				this.userInfo.custodian_relation = e.value[0].label
				this.userInfo.custodian_relation_id = e.value[0].id
				this.show = false
			},
			// 监护人2关系
			custodian_list(e) {
				this.userInfo.custodian_t_relation = e.value[0].label
				this.userInfo.custodian_t_relation_id = e.value[0].id
				this.custodian_show = false
			},
			// 婚姻状况
			confirm_status(e) {
				this.userInfo.marital_status = e.value[0].label
				this.userInfo.marital_s_id = e.value[0].id
				this.showstatus = false
			},
			// 职业
			occupation_list(e) {
				this.userInfo.occupation_relation = e.value[0].label
				this.userInfo.occupation_relation_id = e.value[0].id
				this.showoccupation = false
			},
			changeHandler(e) {
				const {
					columnIndex,
					value,
					values, // values为当前变化列的数组内容
					index,
					// 微信小程序无法将picker实例传出来，只能通过ref操作
					picker = this.$refs.uPicker
				} = e
				// 当第一列值发生变化时，变化第二列(后一列)对应的选项
				if (columnIndex === 0) {
					// picker为选择器this实例，变化第二列对应的选项
					picker.setColumnValues(1, this.columnData[index])
				}
			},
			confirmPicker({
				value
			}, key) {
				this.userInfo[key] = value.join('');
				this.userInfo.kinship = this.userInfo[key]
				this[`show${key[0].toUpperCase() + key.slice(1)}Picker`] = false;
			},
			confirmBirthday({
				value
			}) {
				this.userInfo.birthday = formatDate(value, 'YYYY-MM-DD');
				this.showBirthdayPicker = false;
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			// 新增图片
			async afterRead(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: this.url_phone
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'https://sass-test.doit10019.com/api/upload/uploadOneImage', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							// user: 'test',
							project_id: getApp().globalData.projectId,
							app_id: this.$https.weixinAppId,

						},
						success: (res) => {
							let result = JSON.parse(res.data);
							this.url_phone = result.data.url
							setTimeout(() => {
								resolve(this.url_phone)
							}, 1000)
						}
					});
				})
			},


			sexSelect(e) {
				console.log(e)
			},

			async add() {
				let that = this
				let reg = /^[1][3,4,5,7,8,9][0-9]{9}$/
				if (that.fields_list.name) {
					if (that.fields_list.name.is_required == 1) {
						if (that.userInfo.name == '') {
							uni.showToast({
								title: '请输入姓名',
								icon: 'none'
							})
							return
						}

					}
				}
				if (that.fields_list.sex) {
					if (that.fields_list.sex.is_required == 1) {
						if (that.userInfo.sex == '') {
							uni.showToast({
								title: '请输入性别',
								icon: 'none'
							})
							return
						}
					}
				}
				if (that.fields_list.head_img) {
					if (that.fields_list.head_img.is_required == 1) {
						if (that.url_phone == '') {
							uni.showToast({
								title: '请输入头像',
								icon: 'none'
							})
							return
						}
					}
				}
				if (that.fields_list.custodian) {
					if (that.fields_list.custodian.is_required == 1) {
						if (that.userInfo.custodian == '') {
							uni.showToast({
								title: '请输入监护人',
								icon: 'none'
							})
							return
						}
					}
				}
				if (that.fields_list.custodian_mobile) {
					if (that.fields_list.custodian_mobile.is_required == 1) {
						if (that.userInfo.custodian_mobile == '') {
							uni.showToast({
								title: '请输入监护人手机号',
								icon: 'none'
							})
							return
						}
					}
				}
				if (that.fields_list.custodian_relation) {
					if (that.fields_list.custodian_relation.is_required == 1) {
						if (that.userInfo.custodian_relation == '') {
							uni.showToast({
								title: '请输入监护人关系',
								icon: 'none'
							})
							return
						}
					}
				}
				if (that.fields_list.custodian_t_relation) {
					if (that.fields_list.custodian_t_relation.is_required == 1) {
						if (that.userInfo.custodian_t_relation == '') {
							uni.showToast({
								title: '请输入监护人2关系',
								icon: 'none'
							})
							return
						}

					}
				}
				if (that.fields_list.custodian_t) {
					if (that.fields_list.custodian_t.is_required == 1) {
						if (that.userInfo.custodian_t == '') {
							uni.showToast({
								title: '请输入监护人2名称',
								icon: 'none'
							})
							return
						}

					}
				}
				if (that.fields_list.custodian_t_mobile) {
					if (that.fields_list.custodian_t_mobile.is_required == 1) {
						if (that.userInfo.custodian_t_mobile == '') {
							uni.showToast({
								title: '请输入监护人2手机号',
								icon: 'none'
							})
							return
						}

					}
				}
				if (that.fields_list.address) {
					if (that.fields_list.address.is_required == 1) {
						if (that.userInfo.address == '') {
							uni.showToast({
								title: '请输入详细地址',
								icon: 'none'
							})
							return
						}

					}
				}
				if (that.fields_list.age) {
					if (that.fields_list.age.is_required == 1) {
						if (that.userInfo.age == '') {
							uni.showToast({
								title: '请输入年龄',
								icon: 'none'
							})
							return
						}
					}
				}

				if (that.fields_list.area) {
					if (that.fields_list.area.is_required == 1) {
						if (that.userInfo.area == '') {
							uni.showToast({
								title: '请输入区/县',
								icon: 'none'
							})
							return
						}
					}
				}
				if (that.fields_list.birthday) {
					if (that.fields_list.birthday.is_required == 1) {
						if (that.userInfo.birthday == '') {
							uni.showToast({
								title: '请输入生日',
								icon: 'none'
							})
							return
						}
					}
				}
				if (that.fields_list.company) {
					if (that.fields_list.company.is_required == 1) {
						if (that.userInfo.company == '') {
							uni.showToast({
								title: '请输入公司',
								icon: 'none'
							})
							return
						}
					}
				}

				if (that.fields_list.email) {
					if (that.fields_list.email.is_required == 1) {
						if (that.userInfo.email == '') {
							uni.showToast({
								title: '请输入邮箱',
								icon: 'none'
							})
							return
						}
					}
				}
				if (that.fields_list.graduate) {
					if (that.fields_list.graduate.is_required == 1) {
						if (that.userInfo.graduate == '') {
							uni.showToast({
								title: '请输入学校',
								icon: 'none'
							})
							return
						}
					}
				}

				if (that.fields_list.height) {
					if (that.fields_list.height.is_required == 1) {
						if (that.userInfo.height == '') {
							uni.showToast({
								title: '请输入身高',
								icon: 'none'
							})
							return
						}
					}
				}
				if (that.fields_list.id_card) {
					if (that.fields_list.id_card.is_required == 1) {
						if (that.userInfo.id_card == '') {
							uni.showToast({
								title: '请输入身份证号',
								icon: 'none'
							})
							return
						}
					}
				}
				if (that.fields_list.marital_status) {
					if (that.fields_list.marital_status.is_required == 1) {
						if (that.userInfo.marital_status == '') {
							uni.showToast({
								title: '请输入婚姻状况',
								icon: 'none'
							})
							return
						}
					}
				}
				if (that.fields_list.mobile) {
					if (that.fields_list.mobile.is_required == 1) {
						if (that.userInfo.phone == '') {
							uni.showToast({
								title: '请输入电话号码',
								icon: 'none'
							})
							return
						}
					}
				}
				if (that.fields_list.occupation) {
					if (that.fields_list.occupation.is_required == 1) {
						if (that.userInfo.occupation == '') {
							uni.showToast({
								title: '请输入职业',
								icon: 'none'
							})
							return
						}
					}
				}
				if (that.fields_list.province) {
					if (that.fields_list.province.is_required == 1) {
						if (that.userInfo.province == '') {
							uni.showToast({
								title: '请输入省份',
								icon: 'none'
							})
							return
						}
					}
				}

				if (that.fields_list.street) {
					if (that.fields_list.street.is_required == 1) {
						if (that.userInfo.street == '') {
							uni.showToast({
								title: '请输入街道',
								icon: 'none'
							})
							return
						}
					}
				}
				if (that.fields_list.grade_name) {
					if (that.fields_list.grade_name.is_required == 1) {
						if (that.userInfo.grade_name == '') {
							uni.showToast({
								title: '请输入年级',
								icon: 'none'
							})
							return
						}
					}
				}
				
				if (that.fields_list.class_name) {
					if (that.fields_list.class_name.is_required == 1) {
						if (that.userInfo.class_name == '') {
							uni.showToast({
								title: '请输入班级',
								icon: 'none'
							})
							return
						}
					}
				}

				let formStr = {
					name: this.userInfo.name, //姓名
					sex: this.userInfo.sex, //性别
					age: this.userInfo.age, //年龄
					id_card: this.userInfo.id_card, //身份证号
					mobile: this.userInfo.phone, //电话号码
					height: this.userInfo.height, //身高
					weight: this.userInfo.weight, //体重
					email: this.userInfo.email, //邮箱
					province: this.userInfo.province, //省份
					city: this.userInfo.city, //城市
					area: this.userInfo.area, //区/县
					// street:'',街道
					address: this.userInfo.address, //详细地址
					head_img: this.url_phone, //头像
					custodian: this.userInfo.custodian, //监护人
					custodian_mobile: this.userInfo.custodian_mobile, //监护人手机号
					graduate: this.userInfo.graduate, //毕业学校
					occupation: this.userInfo.occupation_relation_id, //职业
					company: this.userInfo.company, //公司
					marital_status: this.userInfo.marital_s_id, //婚姻状况
					birthday: this.userInfo.birthday, //生日
					custodian_relation: this.userInfo.custodian_relation_id, //监护人关系
					custodian_t_relation: this.userInfo.custodian_t_relation_id, // 监护人2关系
					custodian_t: this.userInfo.custodian_t, //监护人2名称
					custodian_t_mobile: this.userInfo.custodian_t_mobile, //监护人2手机号
					grade_name: this.userInfo.grade_name, //年级
					class_name: this.userInfo.class_name, //班级
				}
				console.log(formStr,'123')

				let postData = {
					student_info: formStr,
					openid: uni.getStorageSync('openid'),
					app_id: this.$https.weixinAppId,
					project_id: getApp().globalData.projectId,
				}
				let res = await train.addStudent(postData)
				if (res.code === 1) {
					
					uni.navigateBack({
						delta: 1
					})
					// uni.navigateTo({
					// 	url:'../student-archives'
					// })
				} else {
					uni.showToast({
							title: res.info,
							icon:'error',
							duration:850
						});
				}


				// if (this.userInfo.name == '') {
				// 	console.log(9978)
				// 	uni.showToast({
				// 		title: '请输入姓名',
				// 		icon: 'none'
				// 	})
				// } else if (this.userInfo.sex != '0' && this.userInfo.sex != '1') {
				// 	uni.showToast({
				// 		title: '请输入性别',
				// 		icon: 'none'
				// 	})
				// } else if (this.userInfo.custodian == '') {
				// 	uni.showToast({
				// 		title: '请输入监护人',
				// 		icon: 'none'
				// 	})
				// } else if (this.userInfo.birthday == '') {
				// 	uni.showToast({
				// 		title: '请输入生日',
				// 		icon: 'none'
				// 	})
				// } else if (this.userInfo.phone == '') {
				// 	uni.showToast({
				// 		title: '请输入手机号',
				// 		icon: 'none'
				// 	})
				// } else if (!reg.test(this.userInfo.phone)) { //判断手机号格式时候正确
				// 	uni.showToast({
				// 		title: '请输入正确的手机号',
				// 		icon: 'none'
				// 	})
				// 	this.userInfo.phone = ''
				// 	return
				// } else if (this.url_phone == '') {
				// 	uni.showToast({
				// 		title: '请上传头像',
				// 		icon: 'none'
				// 	})
				// } else {
				// 	let formStr = {
				// 		name: this.userInfo.name, //姓名
				// 		sex: this.userInfo.sex, //性别
				// 		age: this.userInfo.age, //年龄
				// 		id_card: this.userInfo.id_card, //身份证号
				// 		mobile: this.userInfo.phone, //电话号码
				// 		height: this.userInfo.height, //身高
				// 		weight: this.userInfo.weight, //体重
				// 		email: this.userInfo.email, //邮箱
				// 		province: this.userInfo.province, //省份
				// 		city: this.userInfo.city, //城市
				// 		area: this.userInfo.area, //区/县
				// 		// street:'',街道
				// 		address: this.userInfo.address, //详细地址
				// 		head_img: this.url_phone, //头像
				// 		custodian: this.userInfo.custodian, //监护人
				// 		custodian_mobile: '', //监护人手机号
				// 		graduate: this.userInfo.graduate, //毕业学校
				// 		occupation: this.userInfo.occupation_relation_id, //职业
				// 		company: this.userInfo.company, //公司
				// 		marital_status: this.userInfo.marital_s_id, //婚姻状况
				// 		birthday: this.userInfo.birthday, //生日
				// 		custodian_relation: this.userInfo.custodian_relation_id, //监护人关系
				// 	}
				// 	console.log(formStr)

				// 	// let postData = {
				// 	// 	student_info: formStr,
				// 	// 	openid: uni.getStorageSync('openid'),
				// 	// 	app_id: this.$https.weixinAppId,
				// 	// 	project_id: getApp().globalData.projectId,
				// 	// }
				// 	// let res = await train.addStudent(postData)
				// 	// if (res.code === 1) {
				// 	// 	uni.navigateBack({
				// 	// 		delta: 1
				// 	// 	})
				// 	// 	// uni.navigateTo({
				// 	// 	// 	url:'../student-archives'
				// 	// 	// })
				// 	// }
				// }
			},
		},
	};
</script>

<style lang="scss" scoped>
	.add-student {
		min-height: 100vh;
		background-color: #f6f6f6;
		padding-bottom: calc(150rpx + env(safe-area-inset-bottom));

		/deep/.u-form {
			.u-form-item {
				background-color: #fff;
			}

			.u-form-item__body {
				padding: 30rpx;
			}

			.group {
				margin-top: 20rpx;
			}

			.u-form-item__body__right__message {
				margin-left: 270rpx !important;
			}
		}
	}
</style>
